package com.orkasgb.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.orkasgb.entity.OrkasgbSubProcessEntity;
import com.orkasgb.mapper.OrkasgbSubProcessMapper;
import com.orkasgb.service.IOrkasgbSubProcessService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * 子流程表(TOrkasgbSubProcess)表服务实现类
 *
 * @version 1.0.0
 * @since 2024-09-08 21:17:23
 */
@Slf4j
@Service
public class OrkasgbSubProcessServiceImpl extends ServiceImpl<OrkasgbSubProcessMapper, OrkasgbSubProcessEntity> implements IOrkasgbSubProcessService {

    @Resource
    private OrkasgbSubProcessMapper orkasgbSubProcessMapper;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @Override
    public OrkasgbSubProcessEntity getOrkasgbSubProcess(Serializable id) {
        return this.getBaseMapper().selectById(id);
    }

    /**
     * 通过条件查询多条数据
     *
     * @param orkasgbSubProcessEntity 实体查询参数
     * @return 数据
     */
    @Override
    public List<OrkasgbSubProcessEntity> getOrkasgbSubProcessList(OrkasgbSubProcessEntity orkasgbSubProcessEntity) {
        LambdaQueryWrapper<OrkasgbSubProcessEntity> queryWrapper = new LambdaQueryWrapper<>(OrkasgbSubProcessEntity.class);
        if (orkasgbSubProcessEntity.getProcessId() != null) {
            queryWrapper.eq(OrkasgbSubProcessEntity::getProcessId, orkasgbSubProcessEntity.getProcessId());
        }
        queryWrapper.orderByAsc(OrkasgbSubProcessEntity::getSort);
        return this.getBaseMapper().selectList(queryWrapper);
    }

    /**
     * 通过条件查询多条数据(分页查询)
     *
     * @param orkasgbSubProcessEntity 查询参数实体
     * @return 数据
     */
    @Override
    public List<OrkasgbSubProcessEntity> getOrkasgbSubProcessPageDataList(OrkasgbSubProcessEntity orkasgbSubProcessEntity) {
        LambdaQueryWrapper<OrkasgbSubProcessEntity> queryWrapper = new LambdaQueryWrapper<>(OrkasgbSubProcessEntity.class);
        queryWrapper.eq(OrkasgbSubProcessEntity::getProcessId, orkasgbSubProcessEntity.getProcessId());
        queryWrapper.orderByAsc(OrkasgbSubProcessEntity::getSort);
        IPage<OrkasgbSubProcessEntity> page = new Page<>(orkasgbSubProcessEntity.getCurrent(), orkasgbSubProcessEntity.getPageSize());
        return this.getBaseMapper().selectList(page, queryWrapper);
    }

    /**
     * 新增数据
     *
     * @param orkasgbSubProcessEntity 实体对象
     * @return 新增结果
     */
    @Override
    public int addOrkasgbSubProcess(OrkasgbSubProcessEntity orkasgbSubProcessEntity) {
        return this.getBaseMapper().insert(orkasgbSubProcessEntity);
    }

    /**
     * 修改数据
     *
     * @param orkasgbSubProcessEntity 实体对象
     * @return 修改结果
     */
    @Override
    public int updateOrkasgbSubProcess(OrkasgbSubProcessEntity orkasgbSubProcessEntity) {
        return this.getBaseMapper().updateById(orkasgbSubProcessEntity);
    }

    /**
     * 修改或者新增数据
     *
     * @param orkasgbSubProcessEntityList 实体对象
     * @return 操作结果
     */
    @Override
    public int addOrUpdateOrkasgbSubProcess(List<OrkasgbSubProcessEntity> orkasgbSubProcessEntityList) {
        // 批量新增或修改
        this.getBaseMapper().insertOrUpdate(orkasgbSubProcessEntityList);
        return 0;
    }

    /**
     * 删除数据
     *
     * @param idList 主键结合
     * @return 删除结果
     */
    @Override
    public int deleteOrkasgbSubProcessByIds(List<Long> idList) {
        return this.getBaseMapper().deleteByIds(idList);
    }

}

